package com.scrumtrek.trainings.tdd;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: msuprunov
 * Date: 20.02.13
 * Time: 11:39
 * To change this template use File | Settings | File Templates.
 */
public class Store implements IStore {
    protected ArrayList<Item> items;
    protected PaySystem paySystem;

    public Store(PaySystem paySystem) {
        items = new ArrayList<Item>();
        this.paySystem = paySystem;
    }

    public int getCount() {
        return items.size();
    }

    public void addItem(Item item) {
        items.add(item);
    }

    public boolean existItem(Item item){
        return items.indexOf(item) != -1;
    }

    public void sellItem(Item item) {
        int id = items.indexOf(item);
        if(id != -1){
            items.remove(id);

            paySystem.increaseProfit(item.getPrice());
        }
    }
}
